/**
 * @author yinyuejia
 * @file 封装判断数据类型方法
 */

const prototype = {
  isString(obj: any) {
    return Object.prototype.toString.call(obj) === '[object String]';
  },
  isArray(obj: any) {
    return Object.prototype.toString.call(obj) === '[object Array]';
  },
  isNumber(obj: any) {
    return Object.prototype.toString.call(obj) === '[object Number]';
  },
  isDate(obj: any) {
    return Object.prototype.toString.call(obj) === '[object Date]';
  },
  isBoolean(obj: any) {
    return Object.prototype.toString.call(obj) === '[object Boolean]';
  },
  isObject(obj: any) {
    return Object.prototype.toString.call(obj) === '[object Object]';
  },
  isFunction(obj: any) {
    return Object.prototype.toString.call(obj) === '[object Function]';
  },
  isFile(obj: any) {
    return Object.prototype.toString.call(obj) === '[object File]';
  },
  isNull(obj: any) {
    return Object.prototype.toString.call(obj) === '[object Null]';
  },
  isUndefined(obj: any) {
    return Object.prototype.toString.call(obj) === '[object Undefined]';
  },
  isRegExp(obj: any) {
    return Object.prototype.toString.call(obj) === '[object RegExp]';
  },
  getType(obj: any) {
    const { toString } = Object.prototype;
    const map: any = {
      '[object Boolean]': 'boolean',
      '[object Number]': 'number',
      '[object String]': 'string',
      '[object Function]': 'function',
      '[object Array]': 'array',
      '[object Date]': 'date',
      '[object RegExp]': 'regExp',
      '[object Undefined]': 'undefined',
      '[object Null]': 'null',
      '[object Object]': 'object',
    };
    return map[toString.call(obj)];
  },
};
export default prototype;
